package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanMessage;
import nero.yncc.com.createart.utils.ImageUtils;
import nero.yncc.com.createart.utils.TimeUtils;

/**
 * Created by nero on 2017/7/12.
 */

public class AdapterSiteMessage extends BaseAdapter {
    Context context;
    ArrayList<BeanMessage> arrayList;

    public AdapterSiteMessage(Context context, ArrayList<BeanMessage> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        BeanMessage beanMessage = arrayList.get(i);
        Holder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.adapter_site_message, null);
            holder=new Holder(view);
            view.setTag(holder);
        }else{
            holder=(Holder)view.getTag();
        }

        holder.tv_title.setText(beanMessage.getTitle());
        holder.tv_content.setText(beanMessage.getContent());
        holder.tv_time.setText(TimeUtils.getDateTime(beanMessage.getPublish_time(),"MM-dd HH:mm"));
        ImageUtils.BindImage(context,holder.iv_image,beanMessage.getThumb(),4);
        return view;
    }

    class Holder {
        TextView tv_time, tv_title, tv_content;
        ImageView iv_image;

        public Holder(View root) {
            tv_time=root.findViewById(R.id.tv_time);
            tv_title=root.findViewById(R.id.tv_title);
            tv_content=root.findViewById(R.id.tv_content);
            iv_image=root.findViewById(R.id.iv_image);
        }
    }

}
